package top.hkyzf.study.leetcode.bit;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-1-31 11:20
 */
public class 位1的个数_191 {
    public int hammingWeight(int n) {
        int result = 0;
        while (n != 0) {
            n = n & (n - 1);
            result++;
        }
        return result;
    }

    @Test
    public void testHammingWeight () {
        int n = 0b11111111111111111111111111111101;
        System.out.println(hammingWeight(n));
    }
}
